<?php

class Application_Form_Deliver extends Zend_Form
{

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
    	
    	//subForm $sub_sender
    	$sub_sender = new Zend_Form_SubForm();
    	$unit_size = new Zend_Form_Element_Select("unit_size");
    	$unit_size->setLabel('unit size')   	
    		->setMultiOptions(array('1'=>'13*46*50', '2'=>'23*46*50', '3'=>'43*46*50'))
    		->setRequired(true)->addValidator('NotEmpty', true);
    	
    	$send_name = new Zend_Form_Element_Text("send_name");
    	$send_name->setLabel('name')
    	->setRequired(true)->addValidator('NotEmpty');
    	
    	$send_mobile = new Zend_Form_Element_Text("send_mobile");
    	$send_mobile->setLabel('mobile tel');
    	
    	$send_tel = new Zend_Form_Element_Text("send_tel");
    	$send_tel->setLabel('tel');
    	
    	
    	
    	$send_country = new Zend_Form_Element_Select("send_country");
    	$send_country->setLabel('send country')
    	->setMultiOptions(array('China'=>'China'))
    	->setRequired(true)->addValidator('NotEmpty',true);
    	
    	$send_province = new Zend_Form_Element_Select("send_province");
    	$send_province->setLabel('send province')
    	->setMultiOptions(array('Shanghai'=>'Shanghai'))
    	->setRequired(true)->addValidator('NotEmpty',true);
    	
    	$send_city = new Zend_Form_Element_Select("send_city");
    	$send_city->setLabel('send city')
    	->setMultiOptions(array('Shanghai'=>'Shanghai'))
    	->setRequired(true)->addValidator('NotEmpty',true);
    	
    	$send_district = new Zend_Form_Element_Select("send_district");
    	$send_district->setLabel('send district')
    	->setMultiOptions(array('Yangpu'=>'Yangpu', 'Xuhui'=>'Xuhui', 'Pudong'=>'Pudong'))
    	->setRequired(true)->addValidator('NotEmpty',true);
    	
    	$send_address = new Zend_Form_Element_Text("send_address");
    	$send_address->setLabel('send address')
    	->setRequired(true)->addValidator('NotEmpty',true);
    	
    	$send_zipcode = new Zend_Form_Element_Text("send_zipcode");
    	$send_zipcode->setLabel('send zipcode');
    	
    	
    	
    	$elements1 = array($unit_size,$send_name,$send_mobile,$send_tel,$send_country,$send_province,$send_city,$send_district,$send_address,$send_zipcode);
    	//array_push($array, $elements1);
    	
    	$sub_sender->addElements($elements1);
    	
    	/* $sub_size->addElements(array(
    			new Zend_Form_Element_Text('username', array(
    					'required'   => true,
    					'label'      => 'Username:',
    					'filters'    => array('StringTrim', 'StringToLower'),
    					'validators' => array(
    							'Alnum',
    							array('Regex', false, array('/^[a-z][a-z0-9]{2,}$/'))
    					)
    			)),
    	
    			new Zend_Form_Element_Password('password', array(
    					'required'   => true,
    					'label'      => 'Password:',
    					'filters'    => array('StringTrim'),
    					'validators' => array(
    							'NotEmpty',
    							array('StringLength', false, array(6))
    					)
    			)),
    	)); */
    	
    	
    	//subForm $sub_recipient
    	$sub_recipient = new Zend_Form_SubForm();
    	
    	$rec_name = new Zend_Form_Element_Text("rec_name");
    	$rec_name->setLabel('name')
    	->setRequired(true)->addValidator('NotEmpty');
    	 
    	$rec_mobile = new Zend_Form_Element_Text("rec_mobile");
    	$rec_mobile->setLabel('mobile tel');
    	 
    	$rec_tel = new Zend_Form_Element_Text("rec_tel");
    	$rec_tel->setLabel('tel');
    	 
    	 
    	$rec_country = new Zend_Form_Element_Select("rec_country");
    	$rec_country->setLabel('rec country')
    	->setMultiOptions(array('China'=>'China'))
    	->setRequired(true)->addValidator('NotEmpty',true);
    	 
    	$rec_province = new Zend_Form_Element_Select("rec_province");
    	$rec_province->setLabel('rec province')
    	->setMultiOptions(array('Shanghai'=>'Shanghai'))
    	->setRequired(true)->addValidator('NotEmpty',true);
    	 
    	$rec_city = new Zend_Form_Element_Select("rec_city");
    	$rec_city->setLabel('rec city')
    	->setMultiOptions(array('Shanghai'=>'Shanghai'))
    	->setRequired(true)->addValidator('NotEmpty',true);
    	
    	$rec_district = new Zend_Form_Element_Select("rec_district");
    	$rec_district->setLabel('rec district')
    	->setMultiOptions(array('Yangpu'=>'Yangpu', 'Xuhui'=>'Xuhui', 'Pudong'=>'Pudong'))
    	->setRequired(true)->addValidator('NotEmpty',true);
    	 
    	$rec_address = new Zend_Form_Element_Text("rec_address");
    	$rec_address->setLabel('rec address')
    	->setRequired(true)->addValidator('NotEmpty',true);
    	 
    	$rec_zipcode = new Zend_Form_Element_Text("rec_zipcode");
    	$rec_zipcode->setLabel('rec zipcode');
    	
    	$elements2 = array($rec_name, $rec_mobile, $rec_tel, $rec_country, $rec_province, $rec_city, $rec_district, $rec_address, $rec_zipcode);
    	
    	$sub_recipient->addElements($elements2);
    	
    	//subForm $sub_payment
    	
    	$sub_payment = new Zend_Form_SubForm();
    	
    	$pay_type = new Zend_Form_Element_Select('pay_type');
    	$pay_type->setLabel('pay type')
    	->setMultiOptions(array('Alipay'=>'Alipay', 'Cash'=>'Cash'))
    	->setRequired(true)->addValidator('NotEmpty',true);
    	
    	$elements3 = array($pay_type);
    	
    	$sub_payment->addElements($elements3);
    	
    	
    	
    	
    	$this->addSubForms(array(
    			'sub_sender'  => $sub_sender,
    			'sub_recipient' => $sub_recipient,
    			'sub_payment' => $sub_payment
    	));
    	
    	
    }
    

    /**
     * Prepare a sub form for display
     *
     * @param  string|Zend_Form_SubForm $spec
     * @return Zend_Form_SubForm
     */
    public function prepareSubForm($spec)
    {
        if (is_string($spec)) {
            $subForm = $this->{$spec};
        } elseif ($spec instanceof Zend_Form_SubForm) {
            $subForm = $spec;
        } else {
            throw new Exception('Invalid argument passed to ' . __FUNCTION__ . '()');
        }
        $this->setSubFormDecorators($subForm)
             ->addSubmitButton($subForm)
             ->addSubFormActions($subForm);
        return $subForm;
    }

    /**
     * Add form decorators to an individual sub form
     *
     * @param  Zend_Form_SubForm $subForm
     * @return My_Form_Registration
     */
    public function setSubFormDecorators(Zend_Form_SubForm $subForm)
    {
        $subForm->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
            'Form',
        ));
        return $this;
    }

    /**
     * Add a submit button to an individual sub form
     *
     * @param  Zend_Form_SubForm $subForm
     * @return My_Form_Registration
     */
    public function addSubmitButton(Zend_Form_SubForm $subForm)
    {
        $subForm->addElement(new Zend_Form_Element_Submit(
            'save',
            array(
                'label'    => 'Save and continue',
                'required' => false,
                'ignore'   => true,
            )
        ));
        return $this;
    }

    /**
     * Add action and method to sub form
     *
     * @param  Zend_Form_SubForm $subForm
     * @return My_Form_Registration
     */
    public function addSubFormActions(Zend_Form_SubForm $subForm)
    {
    	//$url = $this->url(array('controller'=>'deliver','action'=>'process'));
    	 
        $subForm->setAction('/box/public/index.php/deliver/process')
                ->setMethod('post');
        return $this;
    }
    

}

